package wator.model.topologies;

import wator.model.IntegerVector;
import wator.model.Topology;

/**
 * This class represents a hyper-torus topology. The universe is connected
 * regarding all dimensions. Therefore, a individual never "falls" out
 * of the universe (i.e. {@link #apply(IntegerVector)}) won't return
 * <code>null</code>).
 */
public class TorusTopology extends Topology {

	/* (non-Javadoc)
	 * @see wator.model.Topology#apply(wator.model.IntegerVector)
	 */
	@Override
	public IntegerVector apply(IntegerVector v) {
		return v.add(sizeVector).mod(sizeVector);
	}

	/* (non-Javadoc)
	 * @see wator.model.Topology#distanceVector(wator.model.IntegerVector, wator.model.IntegerVector)
	 */
	@Override
	public IntegerVector distanceVector(IntegerVector v1, IntegerVector v2) {
		return v2.sub(v1).reduce(sizeVector);
	}
}
